package com.beasts.ant.page.service.content;

import com.beasts.ant.page.entity.content.ApArticle;
import com.beasts.ant.page.repository.content.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Locker
 * @date 25/06/2018 10:33 AM
 * @since 1.0
 */
@Service
public class ArticleServiceImpl implements IArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    @Override
    public ApArticle queryArticle(String id) {
        return articleRepository.findOne(id);
    }

    @Override
    public List<ApArticle> queryArticles() {
        return articleRepository.findAll();
    }

    @Override
    public String insert(ApArticle apArticle) {
        articleRepository.saveAndFlush(apArticle);
        return null;
    }

    @Override
    public String remove(String id) {
        articleRepository.delete(id);
        return null;
    }

    @Override
    public String removes(List<String> ids) {
        articleRepository.deleteByIds(ids);
        return null;
    }

    @Override
    @Transactional
    public String update(ApArticle apArticle) {
        articleRepository.updateById(
                apArticle.getId(),
                apArticle.getTitle()
        );

        return null;
    }
}
